package com.maker.config;


import com.alipay.api.*;
import com.maker.core.AlipayTemplate;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableConfigurationProperties(AlipayProperties.class)
@Configuration
public class AlipayAutoConfiguration {



    @Bean
    public AlipayConfig alipayConfig(AlipayProperties alipayProperties)  {
        AlipayConfig alipayConfig = new AlipayConfig();
        //网关地址
        alipayConfig.setServerUrl(alipayProperties.getGatewayUrl());
        //应用ID
        alipayConfig.setAppId(alipayProperties.getAppId());
        //应用私钥
        alipayConfig.setPrivateKey(alipayProperties.getMerchantPrivateKey());
//        alipayConfig.setEncryptKey(alipayProperties.getEncryptKey());
        //设置支付宝公钥
        alipayConfig.setAlipayPublicKey(alipayProperties.getAlipayPublicKey());
        //设置请求格式
        alipayConfig.setFormat(AlipayConstants.FORMAT_JSON);
        //设置字符集
        alipayConfig.setCharset(AlipayConstants.CHARSET_UTF8);
        //设置签名类型
        alipayConfig.setSignType(AlipayConstants.SIGN_TYPE_RSA2);

        return alipayConfig;
    }

    @Bean
    public AlipayTemplate alipayTemplate(AlipayProperties alipayProperties, AlipayConfig alipayConfig){
        return new AlipayTemplate(alipayProperties,alipayConfig);
    }

}
